home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6401 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  43 lines

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: automatic charrs
  5. Date: Sat, 24 Feb 96 16:28:50 GMT
  6. Organization: none
  7. Message-ID: <825179330snz@genesis.demon.co.uk>
  8. References: <4glp29$dsh@d2.tufts.edu>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4glp29$dsh@d2.tufts.edu>
  15.            rdorich@emerald.tufts.edu "Roberto Dorich" writes:
  16.  
  17. >Hello,
  18. >
  19. >Could someone enlighten me, and tell me why the following program runs
  20. >just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
  21. >
  22. >#include <stdio.h>
  23. >char *b() { return "Hello";}
  24. >main() {
  25. >  char *a=b();
  26. >  a[0]='X';
  27. >  printf("--> %s\n",a);
  28. >}
  29.  
  30. It is illegal to write to a string literal in C (it results in undefined
  31. behaviour. On your system gcc probably puts the string literal in a read-only
  32. segment whereas cc doesn't. Both approaches are valid forms of
  33. undefined behaviour). I'd favour gcc here - it helped to identify a bug
  34. in your program.
  35.  
  36. -- 
  37. -----------------------------------------
  38. Lawrence Kirby | fred@genesis.demon.co.uk
  39. Wilts, England | 70734.126@compuserve.com
  40. -----------------------------------------
  41.